class Solution {
public:
    int subarraySum(vector<int>& nums, int k) {
        unordered_map<int,int> hash;
        int sum = 0,count = 0;
        hash[0] = 1;
        for(auto x : nums)
        {
            sum += x;
            if(hash.count(sum - k))
            count += hash[sum - k];
            hash[sum]++;
        }
        return count;
    }
};
